package com.andyyan.ai.chatbot.mapper;

import com.andyyan.ai.chatbot.model.Conversation;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ConversationMapper {

    String TABLE_NAME = " conversation ";
    String INSERT_COLUMNS = " user_id, conversation_id, name ";
    String SELECT_COLUMNS = " user_id, conversation_id, name ";

    @Select("select " + SELECT_COLUMNS + " from " + TABLE_NAME + " where user_id = #{userId} order by id desc")
    List<Conversation> userConversationList(String userId);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into " + TABLE_NAME + "(" + INSERT_COLUMNS + ") values(#{userId}, #{conversationId}, #{name})")
    int insert(Conversation conversation);

    @Delete("delete from " + TABLE_NAME + " where user_id = #{userId} and conversation_id = #{conversationId}")
    int delete(String userId, String conversationId);

    @Select("select " + SELECT_COLUMNS + " from " + TABLE_NAME + " where user_id = #{userId} and conversation_id = #{conversationId}")
    Conversation queryConversation(String userId, String conversationId);
}
